<?php 
include "/include/common.php";
include APP_PATH . "include/ItemModel.php";

//当前页
$page = !empty($_GET['page']) ? intval($_GET['page']):1;
//$total = 31;
$perpage = 3;


$ItemModle = new ItemModel();
//传值当前页，每页数量，获取分页数据
//总数，列表结果集
$data=$ItemModle -> getPageList($page,$perpage);
$total = $data[0];
$lists = $data[1];


//$lists = $ItemModle->getAllList();
//分类
include APP_PATH . "include/ListModel.php";
$ListModel = new ListModel();
$cats = $ListModel->getAllList();
$scats =[];
foreach($cats as $key =>$val){
    $scats[$val['id']] = $val;
}

//var_dump($cats);
//var_dump($scats);


include APP_PATH ."include/Page.php";
$PageObj = new Page($total, $perpage, $page);
//$pages就是一个HTML的字符串，
$pages = $PageObj->show();
?>

<?php if(!empty($lists)):foreach($lists as $key=>$val): ?>
            <tr>
                <td><?php echo $val['id'];?></td>
                <td><?php echo $scats[$val['cat_id']]['name'];?></td>
                <td><?php echo $val['title'];?></td>
                <td><?php echo $itemStatus[$val['status']]; ?></td>
                <td><a href="/admin/show_edit.php?id=<?php echo $val['id'];?>">编辑</a>
                    <a href="/admin/show_delete.php?id=<?php echo $val['id'];?>">删除</a></td>
            </tr>
<?php endforeach; endif; ?>

